// $$listName: 功能名称=$$listName
// $$dataSize: 数据量=50, 200
import { FakeApi, random } from '@wowon/utils';

const initData = Array.from({ length: random($$dataSize) }).map((_, i) => {
  return {
    name: 'name' + i,
    index: i,
  };
});

export const $$listNameList = new FakeApi(initData, {
  queryType: {
    name: 'like',
    index: 'is',
  },
});

export default {
  /** 查询 */
  'GET /mock/$$listName/query': async (req, res) => {
    const result = await $$listNameList.query(req.query);
    res.json(result);
  },
  /** 新增 */
  'POST /mock/$$listName/create': async (req, res) => {
    const result = await $$listNameList.create(req.body);
    res.json(result);
  },
  /** 更新 */
  'POST /mock/$$listName/update': async (req, res) => {
    const result = await $$listNameList.update(req.body);
    res.json(result);
  },
  /** 删除 */
  'POST /mock/$$listName/remove': async (req, res) => {
    const result = await $$listNameList.remove(req.body);
    res.json(result);
  },
  /** 详情 */
  'POST /mock/$$listName/profile': async (req, res) => {
    const result = await $$listNameList.profile(req.body);
    res.json(result);
  },
};
